<?php get_instance()->view('common/header');?>
<style type="text/css">
    .select2-container .select2-choice{height: 28px !important;padding: 1px 0 0 8px !important;}
    .sort{width: 50px;}
    .content img{max-width: 100% !important;}
    .content .nofloat{max-width: 340px !important;}
</style>
<div class="page-container home">
    <?php get_instance()->view('common/sidebar');?>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <h3 class="page-title"> <?php echo $title ?> </h3>
                    <ul class="page-breadcrumb breadcrumb">
                        <li><i class="fa fa-home"></i><a href="javascript:void(0);"><?php echo $title ?> </a></li>
                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="portlet">
                        <div class="portlet-body">
                            <div class="table-container">
                                <div class="table-actions-wrapper"> <span> </span>
                                    <?php if (adminAuthority('add', 'group')):?>
                                        <a href="<?php echo getUrl('shop/news/add')?>" class="btn btn-sm blue add-btn"><i class="fa fa-plus"></i> 新增</a>
                                    <?php endif;?>
                                </div>
                                <table class="table table-bordered table-hover" id="datatable">
                                    <thead>
                                    <tr role="row" class="heading">
                                        <th> 标题 </th>
                                        <th sort="false">分类</th>
                                        <th sort="false">关键词</th>
                                        <th sort="false">来源</th>
                                        <th width="6%" sort="false">阅读次数</th>
                                        <th sort="false">是否置顶</th>
                                        <th sort="false">状态</th>
                                        <th width="50px" sort="false">排序</th>
                                        <th width="100px" sort="false">添加时间</th>
                                        <th width="150px" sort="false">操作</th>
                                    </tr>
                                    <tr>
                                        <th><input class="form-control form-filter input-sm" name="title" type="text"></th>
                                        <th>
                                            <select name="type_ids" class="form-control form-filter input-sm">
                                                <option value="0" selected>所有</option>
                                                <?php foreach ($category as $k => $v):?>
                                                <option value="<?php echo $v['id']?>"><?php echo $v['type_name']?></option>
                                                <?php endforeach;?>
                                            </select>
                                        </th>
                                        <th><input class="form-control form-filter input-sm" name="keywords" type="text"></th>
                                        <th><input class="form-control form-filter input-sm" name="source" type="text"></th>
                                        <th></th>
                                        <th>
                                            <select name="top" class="form-control form-filter input-sm">
                                                <option value="0" selected>所有</option>
                                                <option value="2">置顶</option>
                                                <option value="1">普通</option>
                                            </select>
                                        </th>
                                        <th>
                                            <select name="status" class="form-control form-filter input-sm">
                                                <option value="0" selected>所有</option>
                                                <option value="2">已发布</option>
                                                <option value="1">未发布</option>
                                            </select>
                                        </th>
                                        <th></th>
                                        <th>
                                            <div class="margin-bottom-5">
                                                <input class="form-control form-filter input-sm" name="send_date_from" dp placeholder="从" type="text">
                                            </div>
                                            <input class="form-control form-filter input-sm" name="send_date_to" dp placeholder="到" type="text" >
                                        </th>
                                        <th> <div class="btn-group">
                                                <a class="btn btn-xs filter-submit btn-default"><i class="fa fa-search"></i> 搜索</a>
                                                <button data-toggle="dropdown" class="btn btn-default dropdown-toggle btn-xs" type="button"><i class="fa fa-angle-down"></i></button>
                                                <ul role="menu" class="dropdown-menu pull-right">
                                                    <li><a href="javascript:void(0);" class="filter-cancel">重置</a></li>
                                                </ul>
                                            </div>
                                        </th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--预览-->
<div id="view-modal" style="top: 20%;" class="modal fade modal_small" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
    <div class="modal-dialog" style="width:400px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title">预览</h4>
            </div>
            <div class="modal-body">
                <div style="width:100%;margin-top: -20px;" class="content">
                </div>
            </div>
            <script type="text/javascript">
                $(function(){
                    var model = $('#model-modal');
                    $('.view-img-btn').live('click', function(){
                        model.find('.driving_license').attr('src', $(this).attr('driving_license'));
                        model.find('.driving_license_copy').attr('src', $(this).attr('driving_license_copy'));
                        model.modal();
                    });
                });
            </script>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function(){

        var model = $('#view-modal');
        $('.preview').live('click', function(){
            var id = $(this).attr('id');
            l_blockUI();
            $.ajax('<?php echo getUrl('shop/news/getInfo');?>', {
                dataType:'json',
                type:'post',
                data:{id:id},
                error:function(){
                    show_message({status:0, message:'请求超时'});
                    App.unblockUI();
                },
                timeout:60000,
                success:function(data,textStatus,jqXHR){

                    if(data.message){
                        show_message(data);
                    }else{
                        model.modal();
//                        console.log(data);
                        var html = '<div class="item" style="border-bottom: 1px solid #ddd;padding-bottom:10px;">';
                        html += '<div><h2>'+data.data.title+'</h2></div>';
                        html += '<div style="color:grey;margin-top:20px;font-size:12px;"><span>信息来源：'+data.data.source+'</span><span style="float: right;">'+data.data.addtime+'</span></div>';
                        html += '</div>';
                        html += '<div class="content" style="font-weight:600;line-height:20px;font-size:13px;">';
                        html +=	data.data.content;
                        html += '</div>';
                        model.find('.content').html(html);
                    }
                    App.unblockUI();
                }
            });
        });
    });
</script>

<script type="text/javascript">
    $(function(){
        datatable_init({
            src: $("#datatable"),
            sAjaxSource: "<?php echo getUrl('shop/news/getList');?>",
            aoColumnDefs : [{
                'bSortable' : false,
                'aTargets' : [0,1,2,3,5,6,9]
            }]
        });

        $('[dp]').not("[noinit]").datepicker({
            changeMonth: true,
            autoclose: true,
            format: "yyyy-mm-dd",
            language: 'zh-CN'
        });

        $("[name='type_ids']").select2();

        $(".sort").live('blur',function () {
            var vl = $(this).val();
            var id = $(this).attr('data-id');
            l_blockUI();
            $.ajax('<?php echo getUrl('shop/news/changeSort');?>', {
                dataType:'json',
                type:'post',
                data:{sort:vl,id:id},
                error:function(){
                    show_message({status:0, message:'请求超时'});
                    App.unblockUI();
                },
                timeout:60000,
                success:function(data,textStatus,jqXHR){
                    show_message(data);
                    $("#datatable").dataTable().fnDraw(true);
                    App.unblockUI();
                }
            });
        });
    });
</script>
</body>
</html>